package com.tedu.guardian.service.impl;

import com.tedu.guardian.mapper.GuardianMapper;
import com.tedu.guardian.pojo.dto.GuardianParam;
import com.tedu.guardian.pojo.entity.Guardian;
import com.tedu.guardian.pojo.vo.GuardianVO;
import com.tedu.guardian.service.GuardianService;
import com.tedu.user.pojo.dto.UserParam;
import com.tedu.user.pojo.vo.UserVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

@Slf4j
@Service
public class GuardianServiceImpl implements GuardianService {
    @Autowired
    GuardianMapper guardianMapper;
    @Override
    @Transactional
    public GuardianVO selectGuardianById(Integer guardianId) {
        log.debug("查询监护人业务,参数:{}",guardianId);
        GuardianVO guardianVO=new GuardianVO();
        guardianVO=guardianMapper.selectGuardianById(guardianId);
        return guardianVO;
    }

    @Override
    public void insertGuardian(UserParam userParam) {
        log.debug("添加监护人业务,参数:{}",userParam);
        Guardian guardian=new Guardian();
        guardian.setName(userParam.getGuardianName());
        guardian.setPhone(userParam.getGuardianPhone());
        guardian.setCreateTime(new Date());
        guardianMapper.insert(guardian);
    }

    @Override
    public void deleteGuardianById(Integer guardianId) {
        log.debug("删除监护人业务,参数:{}",guardianId);
        guardianMapper.deleteById(guardianId);
    }

    @Override
    public void updateGuardian(UserParam userParam) {
        log.debug("更新监护人业务,参数:{}",userParam);
        Guardian guardian=new Guardian();
        guardian.setId(userParam.getGuardianId());
        guardian.setName(userParam.getGuardianName());
        guardian.setPhone(userParam.getGuardianPhone());
        guardian.setUpdateTime(new Date());
        guardianMapper.update(guardian);
    }
}
